package com.copote.common;

import org.springframework.boot.system.ApplicationHome;

/**
 * @ClassName: CommVar
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author: 湖南湘邮科技股份有限公司/RedStar
 * @date: 2023/9/18 10:51
 * @Copyright: 2019 2000 - 2022 HuNan Copote Science & Technology CO., LTD. All Rights Reserved.<br/>
 * 注意：本内容仅限于湖南湘邮科技股份有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
public class CommVar {
    public static final String PDir = "D:/TEMP/PDF/resources";
    public static final String WDir = "D:/TEMP/PDF/results";

    // TODO:取到的文件保存到本地服务器主目录
    private static final String win_FromFilePath = "D:/temp/print/Template/";
    private static final String linux_FromlFilePath = "/home/library/SocketPDF/Template/";
    private static final String win_ToFilePath = "D:/temp/print/tmp/";
    private static String linux_ToFilePath = "/home/library/print/pdf/";
    private static String FromFilePath = null;
    private static String ToFilePath = null;

    public static String getFromFilePath() {
        if (FromFilePath == null || FromFilePath.isEmpty()) {
            setPath();
        }
        return FromFilePath;
    }

    public static String ToFilePath() {
        if (ToFilePath == null || ToFilePath.isEmpty()) {
            setPath();
        }
        String locPath = ToFilePath + "/PDF/" + CommFunc.getNowYMD() + "/";
        CommFunc.mkDir(locPath);
        return locPath;
    }

    private static void setPath() {
        String oString = System.getProperty("os.name").toLowerCase();
        if (oString != null && oString.contains("windows")) {
            FromFilePath = win_FromFilePath;
            ToFilePath = win_ToFilePath;
        } else {
            FromFilePath = linux_FromlFilePath;
            //linux_ToFilePath = ResourceUtils.getURL("classpath:").getPath();
            linux_ToFilePath = new ApplicationHome(CommVar.class).getSource().getParent();//jar所在目录
            ToFilePath = linux_ToFilePath;
        }
        //log.info("FROM:【{}】,TO:【{}】",FromFilePath,ToFilePath);
    }
}
